import java.util.LinkedList;


public class SampleRobot implements IRobot {

	@Override
	public String getName() {

		return "Simple robot";
	}

	@Override
	public int[] nextMove( Board br,Player pl) {
		int obj=pl.getObjective(0);
		for (int i=0;i<10;i++){

			if (br.getPlace(pl.getObjectiveAbs(i)).free==-1){



				obj= pl.getObjective(i);
				break;
			}
		}
		//System.out.println("bot "+Board.player.position+":"+obj);



		double distmax=-10;
		int solsrc=0,soldest=0;
		int candidatsrc;
		boolean bestmove=false;
		double distdebut,distfin=-10;
		for (int i=0;i<10;i++){
			candidatsrc=br.player.getStone(i);

			int var2=br.min_distance_from(0, candidatsrc);

			distdebut=br.min_distance_from(obj, candidatsrc)+var2;
			LinkedList<Integer> ngb=br.player.GetPossibilities(candidatsrc);

			for(int k=0;k<ngb.size();k++){


				distfin = br.min_distance_from(obj, ngb.get(k));
				int var1= br.min_distance_from(0, ngb.get(k));
				if((distdebut-distfin)>distmax   ){
					if(var2>var1){
						distmax=distdebut-distfin;
						solsrc=candidatsrc;
						soldest=ngb.get(k);	
						bestmove=true;
					}else if(!bestmove && !pl.inObjective(candidatsrc)){
						distmax=distdebut-distfin;
						solsrc=candidatsrc;
						soldest=ngb.get(k);	
					}			
				}
			}
		}

		int[] res={solsrc,soldest};
		return res;
	}

}
